import { Agent } from '../../../src/core/Agent.mjs';
import { SearchService } from '../../../src/services/SearchEngine.mjs';

const { describe, test, expect, beforeEach } = await import('@jest/globals');

describe('Agent', () => {
    let agent;
    let mockSearchService;

    beforeEach(async () => {
        mockSearchService = new SearchService();
        await mockSearchService.init();
        
        agent = new Agent({
            searchService: mockSearchService
        });
        await agent.init();
    });

    test('should initialize correctly', () => {
        expect(agent).toBeDefined();
        expect(agent.context.currentTime).toBeDefined();
        expect(agent.context.systemPrompt).toBeDefined();
    });

    test('should process input and generate response', async () => {
        const input = "测试问题";
        const response = await agent.processInput(input);
        
        expect(response).toBeDefined();
        expect(agent.context.conversation.length).toBe(2);
    });

    test('should reset conversation', () => {
        agent.resetConversation();
        expect(agent.context.conversation.length).toBe(0);
    });

    test('should get context', () => {
        const context = agent.getContext();
        expect(context.currentTime).toBeDefined();
        expect(context.systemPrompt).toBeDefined();
        expect(context.conversationLength).toBeDefined();
    });

    test('should format chain of thought', () => {
        const thoughts = [
            { step: "步骤1", content: "内容1" },
            { step: "步骤2", content: "内容2" }
        ];
        
        const formatted = agent.formatChainOfThought(thoughts);
        expect(formatted).toContain("【步骤1】");
        expect(formatted).toContain("【步骤2】");
    });
}); 